/*
============================================================================
Name        : JpegCAppUi.cpp
Author      : Jian
Version     :
Copyright   : Hesine
Description : Main application UI class (controller)
============================================================================
*/

// INCLUDE FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <JpegC.rsg>
#include <f32file.h>
#include <s32file.h>
#include "nmsJpeg.h"
#include "nmsJpegTest.h"

#include <math.h>

#include "JpegC.pan"
#include "JpegCAppUi.h"
#include "JpegCAppView.h"
#include "JpegC.hrh"

// ============================ MEMBER FUNCTIONS ===============================


// -----------------------------------------------------------------------------
// CJpegCAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CJpegCAppUi::ConstructL()
{
    // Initialise app UI with standard value.
    BaseConstructL();

    // Create view object
    iAppView = CJpegCAppView::NewL( ClientRect() );
}
// -----------------------------------------------------------------------------
// CJpegCAppUi::CJpegCAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CJpegCAppUi::CJpegCAppUi()
{
    // No implementation required
}

// -----------------------------------------------------------------------------
// CJpegCAppUi::~CJpegCAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CJpegCAppUi::~CJpegCAppUi()
{
    if ( iAppView )
    {
        delete iAppView;
        iAppView = NULL;
    }

}

// -----------------------------------------------------------------------------
// CJpegCAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//

static void _showNote(const TDesC& aStr) 
{   
    CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote(ETrue);
    informationNote->ExecuteLD(aStr);
}

void CJpegCAppUi::HandleCommandL( TInt aCommand )
{
    switch( aCommand )
    {
    case EEikCmdExit:
    case EAknSoftkeyExit:
        Exit();
        break;
#ifdef __NMS_JPEG_DEBUG
    case EJpegCTest1:
        break;

    case EJpegCTest2:
        {
            if (nmsJpegTest() >= 0) {
                TBuf<40> str ;
                str.Append(_L("Test Succeed and use second: ")) ;
                str.AppendNum(nmsJpegTestGetLastTime()) ;
                _showNote(str) ;
            } else {
                _showNote(_L("Test Failed")) ;
            }
        }
        break;

    case EJpegCTest3:
        {
            const TReal pi=3.14159265358979323846;
            const int total = 200 ;
            TReal cosVal[total];
            
            const int press = 1000 ;

            RFile file ;
            file.Replace(CEikonEnv::Static()->FsSession(), _L("c:\\data\\cosFloat.c"), EFileRead | EFileWrite) ;
            
            TRealFormat rFormat(KDefaultRealWidth, 10) ;
            
            TBuf8<50> tmp ;
            
            file.Write(_L8("static const float _cosVal[200] = {")) ;

            for (int i=0;i<total;i++) {
                cosVal[i]=cos(i*pi/16);
                tmp.Zero() ;
                tmp.AppendNum(cosVal[i], rFormat) ;
                if (i != total -1) 
                    tmp.Append(_L8(", ")) ;

                if (i % 20 == 0) 
                    file.Write(_L8("\r\n    ")) ;
                
                file.Write(tmp) ;
            }

            file.Write(_L8("\r\n} ;")) ;

            file.Close() ;
        }
        break;

    case EJpegCTest4:
        {
            const TReal pi=3.14159265358979323846;
            const int total = 200 ;
            TReal cosVal[total];

            RFile file ;
            file.Replace(CEikonEnv::Static()->FsSession(), _L("c:\\data\\cosInt.c"), EFileRead | EFileWrite) ;

            TBuf8<50> tmp ;

            file.Write(_L8("static const int _cosVal[200] = {")) ;

            for (int i=0;i<total;i++) {
                int val = int(cos(i*pi/16) * (double)10000);
                tmp.Zero() ;
                tmp.AppendNum(val) ;
                if (i != total -1) 
                    tmp.Append(_L8(", ")) ;

                if (i % 20 == 0) 
                    file.Write(_L8("\r\n    ")) ;

                file.Write(tmp) ;
            }

            file.Write(_L8("\r\n} ;")) ;

            file.Close() ;
        }
        break;

#endif

    default:
        Panic( EJpegCUi );
        break;
    }
}
// -----------------------------------------------------------------------------
//  Called by the framework when the application status pane
//  size is changed.  Passes the new client rectangle to the
//  AppView
// -----------------------------------------------------------------------------
//
void CJpegCAppUi::HandleStatusPaneSizeChange()
{
    iAppView->SetRect( ClientRect() );

} 


// End of File
